import { _decorator, Node, tween, Tween, Vec3 } from "cc";

/**
 * 缓动工具
 */
const { ccclass, property } = _decorator;
export class TweenTools {

    /**
     * 放大效果
     */
    public static ScaleBig(_node: Node, _time: number = 0.3, _cb: Function = null) {
        Tween.stopAllByTarget(_node);
        _node.active = true;
        _node.setScale(new Vec3(0, 0, 0));
        tween(_node).to(_time, { scale: new Vec3(1, 1, 1) }, { easing: "quadOut" }).delay(1).to(_time, { scale: new Vec3(0, 0, 0) }, { easing: "backIn" }).call(() => {
            _node.active = false;
            _cb && _cb();
        }).start();
    }

    /**
    * 放大效果不缩小
    */
    public static ScaleBigNoSmall(_node: Node, _time: number = 0.3, _cb: Function = null) {
        Tween.stopAllByTarget(_node);
        _node.setScale(new Vec3(0, 0, 0));
        tween(_node).to(_time, { scale: new Vec3(1, 1, 1) }, { easing: "quadOut" }).call(() => {
            _cb && _cb();
        }).start();
    }

    /**
    * 
    */
    public static Fire1(_node: Node, _time: number = 0.1, _cb: Function = null) {
        Tween.stopAllByTarget(_node);
        _node.setScale(new Vec3(0.6, 0.6, 0.6));
        tween(_node).to(_time, { scale: new Vec3(0.6, 0.4, 0.6) })
            .to(_time, { scale: new Vec3(0.6, 0.6, 0.6) }, { easing: "backOut" })
            .call(() => {
                _cb && _cb();
            }).start();
    }

    /**
    * 
    */
    public static Fire(_node: Node, _time: number = 0.05, _cb: Function = null) {
        Tween.stopAllByTarget(_node);
        _node.setScale(new Vec3(1, 1, 1));
        tween(_node).to(_time, { scale: new Vec3(0.8, 1.2, 1.1) })
            .to(_time, { scale: new Vec3(1, 1, 1) }, { easing: "backOut" })
            .call(() => {
                _cb && _cb();
            }).start();
    }


}


